<template>
  <div class="app-container">
    <div class="header">
        <h1>香港互认基金业务</h1>
    </div>
    <el-divider></el-divider>
    <el-table  :data="stepList"  stripe border>
      <el-table-column label="步骤序号" prop="stepNo"/>
      <el-table-column label="步骤类型" prop="stepType"/>
      <el-table-column label="步骤名称" prop="stepName"/>
      <el-table-column label="执行日期" prop="stepDate">
        <template #default="scope">
          <el-date-picker v-model="scope.row.stepDate" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="link" @click="executeTask(scope.row)">执行</el-button>
          <el-button link type="primary" icon="search" @click="showTaskList(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="结果展示" v-model="dialogVisible">
      <el-table :data="DialogTableList">
        <el-table-column v-for="(item,index) in DialogTableColumn" :key="index" :prop="item.prop" :label="item.label"/>
      </el-table>
      <pagination

        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>
  </div>

</template>

<script setup>
  import {parseTime} from "@/utils/ruoyi";
  import {importData, listExchangerate} from "@/api/operation/exchangerate"
  import {reactive} from "vue";
  const stepList = ref([
    {
      "stepNo":1,
      "stepType":"exchangeRate",
      "stepName":"获取今日汇率",
      "stepDate":parseTime(new Date(), "{y}-{m}-{d}")
    },
    {
      "stepNo":2,
      "stepType":"estimateDate",
      "stepName":"倒入estimate数据",
      "stepDate":parseTime(new Date(), "{y}-{m}-{d}")
    },
    {
      "stepNo":3,
      "stepType":"finalDate",
      "stepName":"导入final数据",
      "stepDate":parseTime(new Date(), "{y}-{m}-{d}")
    },
    {
      "stepNo":4,
      "stepType":"CSVDate",
      "stepName":"导入CSV文件",
      "stepDate":parseTime(new Date(), "{y}-{m}-{d}")
    },
    {
      "stepNo":5,
      "stepType":"Count",
      "stepName":"计算百分比",
      "stepDate":parseTime(new Date(), "{y}-{m}-{d}")
    },
  ]);
  const dialogVisible = ref(false);
  const {proxy} = getCurrentInstance();
  const DialogTableList = ref([]);
  const DialogTableColumn =  ref([]);
  const total = ref(0);
  const queryParams = reactive({
    "pageNum":1,
    "pageSize":10,
    "natureday":"",
    "stepDate":"",
    "stepType":""
  });

  const exchangeRateColumn = [
    {
      "prop":"natureday",
      "label":"日期"
    },
    {
      "prop":"originalcurrency",
      "label":"三位本币币种代码"
    },
    {
      "prop":"valuationcurrency",
      "label":"三位外币币种代码"
    },
    {
      "prop":"exchangerate",
      "label":"汇率"
    }
  ];

  const executeTask = (data)=>{
    switch (data.stepType){
      case "exchangeRate":
        let executeParam = {
          "stepDate":parseTime(data.stepDate, "{y}{m}{d}"),
          "stepType":"exchangeRate",
        }
        importData(executeParam).then(res=>{
          proxy.$modal.msgSuccess(res.msg);
        })
        console.log(data)
        break;
      case "estimateDate":
        console.log(data)
        break;
      case "finalDate":
        console.log(data)
        break;
      case "CSVDate":
        console.log(data)
        break;
      case "Count":
        console.log(data)
        break;
    }
  }
  const showTaskList = (data)=>{
    queryParams.stepDate = data.stepDate
    queryParams.natureday = parseTime(data.stepDate, "{y}{m}{d}")
    dialogVisible.value = true;
    switch (data.stepType){
      case "exchangeRate":
        queryParams.stepType = "exchangeRate";
        listExchangerate(queryParams).then(res=>{
          DialogTableColumn.value = exchangeRateColumn
          DialogTableList.value = res.rows
          total.value = res.total;
        })
        break;
      case "estimateDate":
        DialogTableColumn.value = []
        DialogTableList.value = []
        total.value = 0
        console.log(data)
        break;
      case "finalDate":
        console.log(data)
        break;
      case "CSVDate":
        console.log(data)
        break;
      case "Count":
        console.log(data)
        break;
    }
  }
  const getList =()=>{
    showTaskList(queryParams)
  }
</script>
<style scoped lang="scss">

</style>
